package com.design;

/**
 * Builder模式
 * @author zhuangqi
 * @date 2017/5/15.
 */
public class NutritionFacts {
    private final int servingSize;
    private final int servings;
    private final int calories;
    private final int fat;
    private final int sodium;
    private final int carbohydrate;

    public static class Builder {
        private final int servingSize;
        private final int servings;
        private int calories;
        private int fat;
        private int sodium;
        private int carbohydrate;

        public Builder(int servingSize, int servings) {
            this.servingSize = servingSize;
            this.servings = servings;
        }
        public Builder calories(int var){
            calories = var; return this;
        }
        public Builder fat(int var){
            fat = var; return this;
        }
        public Builder sodium(int var){
            sodium = var; return this;
        }
        public Builder carbohydrate(int var){
            carbohydrate = var; return this;
        }
        public NutritionFacts build(){
            return new NutritionFacts(this);
        }

    }
    public NutritionFacts(Builder builder)
    {
        servingSize = builder.servingSize;
        servings = builder.servings;
        calories = builder.calories;
        fat = builder.fat;
        sodium = builder.sodium;
        carbohydrate = builder.carbohydrate;
    }

    public static void main(String[] args) {
        NutritionFacts nutritionFacts = new NutritionFacts.Builder(240,8).calories(123).build();
    }
}
